package cn.fzkj.framework.config;

import com.baomidou.mybatisplus.extension.plugins.OptimisticLockerInterceptor;
import com.baomidou.mybatisplus.extension.plugins.PaginationInterceptor;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@MapperScan("cn.fzkj.project")
public class MybatisPlusConfig {
    // 乐观锁
    @Bean
    public OptimisticLockerInterceptor optimisticLockerInterceptor(){
        return new OptimisticLockerInterceptor();
    }

    // 分页请求拦截器
    @Bean
    public PaginationInterceptor paginationInterceptor() {
        PaginationInterceptor paginationInterceptor = new PaginationInterceptor();
//        paginationInterceptor.setLimit(10); //
//        paginationInterceptor.setOverflow(true); //
        return paginationInterceptor;

    }

    /**
     * SQL执行效率插件
     */
//    @Bean
//    @Profile({"dev","test"}) // 设置 dev test 环境开启,保证效率
//    public PerformanceInterceptor performanceInterceptor() {
//        PerformanceInterceptor performanceInterceptor = new PerformanceInterceptor();
//        performanceInterceptor.setMaxTime(100);    // ms 设置 SQL 执行的最大时间，如果超过了就不执行
//        performanceInterceptor.setFormat(true);      //    开启格式化支持
//        return performanceInterceptor;
//    }
}
